/*
 * FieldOT.java
 *
 * $Id: FieldOT.java,v 1.2 2009-09-29 11:34:44 mario Exp $
 */
package org.ceteca.explica.core.installer;

/**
 * ValueObject with the data of a Field item.
 * <br/>
 * Responsibilities:
 * <ul>
 *  <li>Store the field data.</li>
 * </ul>
 * <br/>
 * @author Mario García García <mario@imagos.es>
 * Copyright (c) 2008 Fundación Centro Tecnolóxico da Carne
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * <br/>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * <br/>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
public class FieldOT {
	/** Field id. It must be the same as the name of the database field. */
	private String id;
	/** Field name that will be showed to the user. */
	private String name;
	/** Flag to show if the entity can be queried by this field. */
	private boolean searchable;
	/** Field visibility. It will be true when the field is visible in the table of
	 * entity fields, or false when it won't be shown.
	 */
	private boolean visible;
	/** Entity detail entity search. It enables the entity query by a subentity detail field. It
	 * holds the name of the detail entity the query will be searched by.
	 */
	private String detailEntity;
	/** Entity detail field search. It enables the entity query by a subentity detail field. It
	 * holds the name of the detail field the query will be searched by.
	 */
	private String detailField;
	
	/**
	 * FieldOT constructor. It initializes all the field values.
	 * @param id String, field id.
	 * @param name String, field name.
	 * @param searchable boolean, shows if queries by the field are allowed.
	 */
	public FieldOT(String id, String name, boolean searchable) {
		this.setId(id);
		this.setName(name);
		this.setSearchable(searchable);
		this.setVisible(true);
		this.setDetailEntity(null);
		this.setDetailField(null);
	}
	
	/**
	 * FieldOT constructor. It initializes all the field values.
	 * @param id String, field id.
	 * @param name String, field name.
	 * @param searchable String, shows if queries by the field are allowed.
	 */
	public FieldOT(String id, String name, String searchable) {
		this.setId(id);
		this.setName(name);
		this.setSearchable(Boolean.parseBoolean(searchable));
		this.setVisible(true);
		this.setDetailEntity(null);
		this.setDetailField(null);
	}
	
	/**
	 * FieldOT constructor. It initializes all the field values.
	 * @param id String, field id.
	 * @param name String, field name.
	 * @param searchable String, shows if queries by the field are allowed.
	 * @param visible String, true if the field is shown in the entity table or
	 * false otherwise.
	 * @param detailEntity String, name of the detail entity for the query.
	 * @param detailField String, name of the detail entity field for the query. 
	 */
	public FieldOT(String id, String name, String searchable, String visible, String detailEntity, String detailField) {
		this.setId(id);
		this.setName(name);
		this.setSearchable(Boolean.parseBoolean(searchable));
		this.setVisible(Boolean.parseBoolean(visible));
		this.setDetailEntity(detailEntity);
		this.setDetailField(detailField);
	}
	
	/**
	 * Gets the field id.
	 * @return String, field id.
	 */
	public String getId() {
		return id;
	}
	/**
	 * Sets up the field id.
	 * @param id String, field id.
	 */
	public void setId(String id) {
		this.id = id;
	}
	/**
	 * Gets the field name.
	 * @return String, field name.
	 */
	public String getName() {
		return name;
	}
	/**
	 * Sets up the field id.
	 * @param name String, field name.
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * Gets the value of the field searchable flag.
	 * @return boolean, True if queries by the field are allowed;
	 * False in any other case.
	 */
	public boolean isSearchable() {
		return searchable;
	}
	/**
	 * Sets up the value of the field searchable flag.
	 * @param searchable boolean, True to allow queries by the field;
	 * False in any other case.
	 */
	public void setSearchable(boolean searchable) {
		this.searchable = searchable;
	}
	
	/**
	 * Gets the entity visibility
	 * @return boolean, True if the field is visible; False otherwise.
	 */
	public boolean isVisible() {
		return visible;
	}
	/**
	 * Sets up the entity visibility
	 * @param visible boolean, True if the field is visible; False otherwise.
	 */
	public void setVisible(boolean visible) {
		this.visible = visible;
	}
	
	/**
	 * Gets the entity detail entity of the search.
	 * @return String, Name of the detail entity to enable the query by; null in
	 * case no detail search enabled.
	 */
	public String getDetailEntity() {
		return detailEntity;
	}
	/**
	 * Sets up the entity detail of the search.
	 * @param detailEntity String, Name of the detail entity to enable the query by; null in
	 * case no detail search enabled.
	 */
	public void setDetailEntity(String detailEntity) {
		this.detailEntity = detailEntity;
	}

	/**
	 * Gets the entity detail field of the search.
	 * @return String, Name of the detail entity field to enable the query by; null in
	 * case no detail search enabled.
	 */
	public String getDetailField() {
		return detailField;
	}
	/**
	 * Sets up the entity detail field of the search.
	 * @param detailField String, Name of the detail entity field to enable the query by; null in
	 * case no detail search enabled.
	 */
	public void setDetailField(String detailField) {
		this.detailField = detailField;
	}
	
	/**
	 * Returns tag Id assigned to CVS source file.
	 */
	public static String getRevision() {
		return "$Id: FieldOT.java,v 1.2 2009-09-29 11:34:44 mario Exp $";
	}
}
